package com.xyht.sca_s.student_manage_system.modules.advanceRegistration.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.entity.req.RxAdvanceRegistrationMiddleSchoolClassesDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.entity.req.RxAdvanceRegistrationMiddleSchoolClassesUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.entity.req.RxAdvanceRegistrationMiddleSchoolReq;
import com.xyht.sca_s.student_manage_system.modules.advanceRegistration.service.RxAdvanceRegistrationMiddleSchoolService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 招生预报名初中学校 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-04-12
 */
@RestController
@RequestMapping("/advanceRegistration/middleSchool")
@SecretBody
public class RxAdvanceRegistrationMiddleSchoolController {

    @Resource
    private RxAdvanceRegistrationMiddleSchoolService middleSchoolService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("添加初中学校")
    @PostMapping("/add")
    public ResponseResult addMiddleSchool(@RequestBody RxAdvanceRegistrationMiddleSchoolReq addReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return middleSchoolService.addMiddleSchool(addReq, userId);
    }

    @ApiOperation("删除初中学校")
    @PostMapping("/deleted")
    public ResponseResult deletedMiddleSchool(@RequestBody RxAdvanceRegistrationMiddleSchoolReq deletedReq) {
        return middleSchoolService.deletedMiddleSchool(deletedReq);
    }

    @ApiOperation("修改初中学校")
    @PostMapping("/update")
    public ResponseResult updateMiddleSchool(@RequestBody RxAdvanceRegistrationMiddleSchoolReq updateReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return middleSchoolService.updateMiddleSchool(updateReq,userId);
    }

    @ApiOperation("查看初中学校列表")
    @GetMapping("/list")
    @RequestPass
    public ResponseResult getMiddleSchoolList(@RequestParam(value = "searchStr",required = false) String searchStr,
                                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return middleSchoolService.getMiddleSchoolList(pageNum,pageSize,searchStr);
    }

    @ApiOperation("修改班级")
    @PostMapping("/updateClasses")
    public ResponseResult updateMiddleSchoolClasses(@RequestBody RxAdvanceRegistrationMiddleSchoolClassesUpdateReq updateReq) {
        return middleSchoolService.updateMiddleSchoolClasses(updateReq);
    }

    @ApiOperation("批量删除初中学校下的班级")
    @PostMapping("/deletedClasses")
    public ResponseResult deletedMiddleSchoolClasses(@RequestBody RxAdvanceRegistrationMiddleSchoolClassesDeletedReq deletedReq) {
        return middleSchoolService.deletedMiddleSchoolClasses(deletedReq);
    }

    @ApiOperation("查看初中学校下的班级列表")
    @GetMapping("/getClassesList")
    public ResponseResult getMiddleSchoolClassesList(@RequestParam(value = "middleSchoolId") String middleSchoolId,
                                                     @RequestParam(value = "searchStr",required = false) String searchStr,
                                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return middleSchoolService.getMiddleSchoolClassesList(pageNum,pageSize,searchStr,middleSchoolId);
    }

}

